added Feb 2001 SDK
[windows-sources.git] / shared source / sscli20 / jscript / engine / jsprototypefield.cs
blobf549854ae372e025710771a20e14502c3083a4ae
1 // ==++==
2 //
3 //
4 // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
5 //
6 // The use and distribution terms for this software are contained in the file
7 // named license.txt, which can be found in the root of this distribution.
8 // By using this software in any fashion, you are agreeing to be bound by the
9 // terms of this license.
10 //
11 // You must not remove this notice, or any other, from this software.
12 //
13 //
14 // ==--==
17 An object with a prototype acts as if the properties of its prototype are its own. Any updates to the properties of the prototype are
18 visible via the object. However, if the property is assigned to via the object, the object makes a local copy of the property and all
19 further accesses via the object refer to the local copy, not the field of the prototype. Any further updates to the corresponding property
20 of the prototype will no longer be visible via the object. Likewise, updates via the object do not update the corresponding property on the prototype.
22 This class provides a wrapper for the fields of prototype properties that implements the desired behavior. When an object is queried for
23 a property and finds it in its prototype chain, it wraps the prototype property in one these and adds it to its field table. All future accesses
24 to the property resolve to this field.
26 Static fields and read only fields are not wrapped since they should not behave like instance fields.
29 namespace Microsoft.JScript {
31 using System;
32 using System.Globalization;
33 using System.Reflection;
35 internal sealed class JSPrototypeField : JSField{
36 private Object prototypeObject;
37 internal FieldInfo prototypeField;
38 internal Object value;
40 internal JSPrototypeField(Object prototypeObject, FieldInfo prototypeField){
41 this.prototypeObject = prototypeObject;
42 this.prototypeField = prototypeField;
43 this.value = Missing.Value;
46 public override FieldAttributes Attributes{
47 get{
48 return FieldAttributes.Public|FieldAttributes.Static;
52 public override Object GetValue(Object obj){
53 if (this.value is Missing) //The field has not been written to, defer to the prototype.
54 return this.prototypeField.GetValue(this.prototypeObject);
55 else
56 return this.value;
59 public override String Name{
60 get{
61 return this.prototypeField.Name;
65 public override void SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, CultureInfo locale){
66 this.value = value;